﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    using DAL.Entities;

    public class LoaidichvuDAL : BaseDAL, UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT * FROM loaidichvu";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @"DELETE FROM loaidichvu WHERE maloaidichvu = '{0}'";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (loaidichvu)obj;
            string sql = @"INSERT INTO loaidichvu(maloaidichvu,tenloaidichvu) VALUES('{0}',N'{1}')";
            sql = string.Format(sql, o.maloaidichvu, o.tenloaidichvu);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (loaidichvu)obj;
            string sql = @"UPDATE loaidichvu SET tenloaidichvu='{0}' where maloaidichvu='{1}'";
            sql = string.Format(sql, o.tenloaidichvu, o.maloaidichvu);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        public string Select_max()
        {
            string sql = @"SELECT max(substring(maloaidichvu,4,LEN(MALOAIDICHVU)-3)) as id FROM loaidichvu";
            DataTable dt = ExecuteQuery(sql);
            return dt.Rows.Count > 0 ? dt.Rows[0]["id"] + "" : "0";
            
        }



        public bool deleteobj(object obj)
        {
            throw new NotImplementedException();
        }
    }
}
